<% 
  var headContent = {
%>
<!-- //这里包含需要引入的其他css/js文件 -->
<style>
 /*验证：提示信息样式 begin*/
 .am-alert-danger {
    background-color: transparent;
    border-color: transparent;
    color: red;
  }
  .am-alert {
    margin-bottom: 1em;
    padding: .625em;
    background: transparent;
    border: none;
    border-radius: 0;
  }
  /*验证：提示信息样式 end*/
  /*附件上传*/
  .am-progress-xs {
    height: .2rem;
  }
  .am-progress {
    margin-bottom: 0;
  }
</style>
<%};%>
<%layout("/common/_layout.html",{head:headContent}){%>
<div>
  <% include("/admin/waiting_hint.tpl"){}%></div>
<input type="hidden" id="type" name="type" value="${type!''}" />

<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg" onclick="location.href='${base}/multiUserAuthConfig/list';">系统管理</strong>
    /
    <small>多用户登录权限配置</small>
     /
    <small>按照门店、人员、渠道等授权</small>
  </div>
</div>
<div class="am-tabs am-margin" id="tab-container" data-am-tabs>
  <ul class="am-tabs-nav am-nav am-nav-tabs">
    <!--<li id="li-city"  class="am-active">
      <a href="#tab-city">地市授权</a>
    </li>-->
    <li id="li-org" class="am-active">
      <a href="#tab-org">门店授权</a>
    </li>
    <li id="li-member">
      <a href="#tab-member">人员授权</a>
    </li>
    <!--
    <li id="li-channel-class">
      <a href="#tab-channel-class">渠道大类授权</a>
    </li>
    <li id="li-channel-cluster">
      <a href="#tab-channel-cluster">渠道簇授权</a>
    </li>-->
    <li id="li-channel-type">
      <a href="#tab-channel-type">渠道小类授权</a>
    </li>
  </ul>
  <div class="am-tabs-bd">
  
  
  <!--
   <div class="am-tab-panel am-fade am-in am-active" id="tab-city">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <%if(so.hasPermission("THEMES_AUTH_CITY_ADD")) {%>
              <button type="button" class="am-btn am-btn-default" id="add-city-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <%}%>
              <%if(so.hasPermission("THEMES_AUTH_CITY_DEL")) {%>
              <button type="button" id="deleteButtonCity" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteSelected(1)">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <%}%></div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keyword-city" value="${keywordCity!}" placeholder="按地市名称或渠道编码搜索">
            <span class="am-input-group-btn">
              <button  id="query-city-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckCity"/>
                  </th>
                  <th class="table-title">地市</th>
                  <th class="table-title">渠道编码</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(cityPager)) {for(list in cityPager.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsCity" value="${list.id}"></td>
                  <td >${list.DisplayName}</td>
                  <td >${list.NumCode}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(cityPager) && cityPager.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/business_auth_config_input_city_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>
    -->
    
    
    <div class="am-tab-panel am-fade am-in am-active" id="tab-org">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <%if(so.hasPermission("THEMES_AUTH_ORG_ADD")) {%>
              <button type="button" class="am-btn am-btn-default" id="add-store-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <%}%>
              <%if(so.hasPermission("THEMES_AUTH_ORG_DEL")) {%>
              <button type="button" id="deleteButtonStore" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteSelected(2)">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <%}%></div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keyword-org" value="${keywordOrg!}" placeholder="按名称或渠道编码搜索">
            <span class="am-input-group-btn">
              <button  id="query-org-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckStore"/>
                  </th>
                  <th class="table-title">门店名称</th>
                  <th class="table-title">渠道编码</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(storePager)) {for(list in storePager.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsStore" value="${list.id}"></td>
                  <td >${list.DisplayName}</td>
                  <td >${list.NumCode}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(storePager) && storePager.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/business_auth_config_input_store_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>
    
    <div class="am-tab-panel am-fade am-in" id="tab-member">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <button type="button" class="am-btn am-btn-default" id="add-member-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <button type="button" id="deleteButtonMember" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteSelected(3)">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <button type="button" id="deleteAllMember" class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" onclick="deleteAll(3)" data-am-dropdown-toggle>
                <span class="am-icon-trash-o"></span>
                一键删除
              </button>


              </div>

            <div class="am-btn-group am-btn-group-xs">
              <div class="am-btn-group am-btn-group-xs am-form-file">
                <button type="button" id="bt_import" class="am-btn am-btn-default">
                  <span class="am-icon-archive"></span>
                  导入
                </button>
                <input id="doc-form-file" type="file" name="import" onChange=ajaxUploadFileWithLocalhost('doc-form-file','${base}/multiUserAuthConfig/upload?') multiple></div>
            </div>

            <div class="am-dropdown" data-am-dropdown>
              <button id="templateDownload" type="button" class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle>
                <span class="am-icon-download"></span>
                模板
              </button>
            </div>

          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keyword-member" value="${keywordMember!}" placeholder="按姓名\工号\手机号搜索">
            <span class="am-input-group-btn">
              <button  id="query-member-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckMember"/>
                  </th>
                  <th class="table-title">姓名</th>
                  <th class="table-title">工号</th>
                  <th class="table-title">手机号</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(memberPager)) {for(list in memberPager.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsMember" value="${list.id}"></td>
                  <td >${list.name}</td>
                  <td >${list.emp_code}</td>
                  <td >${list.mobile}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(memberPager) && memberPager.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/business_auth_config_input_member_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>
    


<!--
    <div class="am-tab-panel am-fade am-in" id="tab-channel-class">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <%if(so.hasPermission("THEMES_AUTH_ORG_ADD")) {%>
              <button type="button" class="am-btn am-btn-default" id="add-class-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <%}%>
              <%if(so.hasPermission("THEMES_AUTH_ORG_DEL")) {%>
              <button type="button" id="deleteButtonClass" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteSelected(4)">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <%}%></div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keywords-channel-class" value="${keywordChannelClass!}" placeholder="按渠道名称或编码搜索">
            <span class="am-input-group-btn">
              <button  id="query-class-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckChannelClass"/>
                  </th>
                  <th class="table-title">渠道大类名称</th>
                  <th class="table-title">渠道大类编码</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(classPager)) {for(list in classPager.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsChannelClass" value="${list.id}"></td>
                  <td >${list.class_name}</td>
                  <td >${list.WebsiteId}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(classPager) && classPager.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/business_auth_config_input_channel_class_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>
    
    <div class="am-tab-panel am-fade am-in" id="tab-channel-cluster">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <%if(so.hasPermission("THEMES_AUTH_ORG_ADD")) {%>
              <button type="button" class="am-btn am-btn-default" id="add-cluster-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <%}%>
              <%if(so.hasPermission("THEMES_AUTH_ORG_DEL")) {%>
              <button type="button" id="deleteButtonCluster" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteSelected(5)">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <%}%></div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keywords-channel-cluster" value="${keywordChannelCluster!}" placeholder="按渠道名称或者编码搜索">
            <span class="am-input-group-btn">
              <button  id="query-cluster-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckChannelCluster"/>
                  </th>
                  <th class="table-title">渠道簇名称</th>
                  <th class="table-title">渠道簇编码</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(clusterPager)) {for(list in clusterPager.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsChannelCluster" value="${list.id}"></td>
                  <td >${list.class_name}</td>
                  <td >${list.WebsiteId}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(clusterPager) && clusterPager.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/business_auth_config_input_channel_cluster_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>
 -->
 
    
    <div class="am-tab-panel am-fade am-in" id="tab-channel-type">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <%if(so.hasPermission("THEMES_AUTH_ORG_ADD")) {%>
              <button type="button" class="am-btn am-btn-default" id="add-type-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <%}%>
              <%if(so.hasPermission("THEMES_AUTH_ORG_DEL")) {%>
              <button type="button" id="deleteButtonType" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteSelected(6)">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <%}%></div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keywords-channel-type" value="${keywordChannelType!}" placeholder="按渠道名称或编码搜索">
            <span class="am-input-group-btn">
              <button  id="query-type-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckChannelType"/>
                  </th>
                  <th class="table-title">网点Id</th>
                  <th class="table-title">名称</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(typePager)) {for(list in typePager.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsChannelType" value="${list.id}"></td>
                  <td >${list.WebsiteId}</td>
                  <td >${list.class_name}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(typePager) && typePager.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/business_auth_config_input_channel_type_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>
    
    
  </div>
</div>
<!--
<div class="am-margin">
  <button type="button" class="am-btn am-btn-warning am-btn-xs" onclick="History.back();">返回上一级</button>
</div>-->

<script src="${base}/template/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
<script src="${base}/template/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
<script src="${base}/template/jQuery-File-Upload/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="${base}/template/lhgdialog/lhgdialog.min.js"></script>
<script type="text/javascript">
    var urlBase = "${base}";
    var type = $("#type").val();
    $(function() {
      var typearr = {"2":1,"3":2,"6":3};
	  $("#tab-container").tabs('open',typearr[type+""]-1);
      //门店新增按钮
      $('#add-store-btn').dialog({
        content: 'url:${base}/multiUserAuthConfig/dialogStore', 
        title: '门店选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
            if (backdata.length > 0) {
              console.log("id:" + backdata[0].id + ",NumCode:" + backdata[0].NumCode+",DispalyName:"+backdata[0].DispalyName);
              addAuthOrizationByType(2,objProp2Arr(backdata),query);
            }
        }
      });
      
      /*
      //地市新增按钮
      $('#add-city-btn').dialog({
        content: 'url:${base}/businessAuthConfig/dialogCity',
        title: '地市选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
        	console.info(backdata);
            addAuthOrizationByType(1,backdata,query);
        }
      });
      */
      
      
      //人员新增按钮
      $('#add-member-btn').dialog({
        content: 'url:${base}/multiUserAuthConfig/dialogMember', 
        title: '人员选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
            if (backdata.length > 0) {
              console.info(backdata);
              console.log("id:" + backdata[0].id + ",name:" + backdata[0].name + ",emp_code:"+ backdata[0].emp_code+",mobile:"+backdata[0].mobile);
              addAuthOrizationByType(3,objProp2Arr(backdata),query);
            }
        }
      });
      /*
      //渠道大类新增按钮
      $('#add-class-btn').dialog({
        content: 'url:${base}/multiUserAuthConfig/dialogChannel?type=4', 
        title: '渠道大类选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
            if (backdata.length > 0) {
              console.log("id:" + backdata[0].id + ",class_name:" + backdata[0].class_name+",websiteId="+backdata[0].websiteId);
              addAuthOrizationByType(4,objProp2Arr(backdata),query);
            }
        }
      });
      
      //渠道簇新增按钮
      $('#add-cluster-btn').dialog({
        content: 'url:${base}/multiUserAuthConfig/dialogChannel?type=5', 
        title: '渠道簇选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
            console.log("id:" + backdata[0].id + ",class_name:" + backdata[0].class_name+",websiteId="+backdata[0].websiteId);
            addAuthOrizationByType(5,objProp2Arr(backdata),query);
        }
      });
      */
      
      
      //渠道小类新增按钮
      $('#add-type-btn').dialog({
        content: 'url:${base}/multiUserAuthConfig/dialogChannel?type=6', 
        title: '渠道小类选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
            if (backdata.length > 0) {
              console.log("id:" + backdata[0].id + ",class_name:" + backdata[0].class_name+",websiteId="+backdata[0].websiteId);
              addAuthOrizationByType(6,objProp2Arr(backdata),query);
            }
        }
      });



/*
     $("#query-city-btn").on("click",function(){
        query(1);
      }); 
*/      
      $("#query-org-btn").on("click",function(){
        query(2);
      }); 
        
      $("#query-member-btn").on("click",function(){
        query(3);
      });  
      
  /*    
      $("#query-class-btn").on("click",function(){
        query(4);
      }); 
      
      $("#query-cluster-btn").on("click",function(){
        query(5);
      });
  */      
      $("#query-type-btn").on("click",function(){
        query(6);
        
      }); 

  /*    
    $("#allCheckCity").click(function() {
        toggleStatus("idsCity","deleteButtonCity",this.checked);
    });*/
    $("#allCheckStore").click(function() {
        toggleStatus("idsStore","deleteButtonStore",this.checked);
    });
	$("#allCheckMember").click(function() {
        toggleStatus("idsMember","deleteButtonMember",this.checked);
	});
	/*
    $("#allCheckChannelClass").click(function() {
	    toggleStatus("idsChannelClass","deleteButtonClass",this.checked);
    });
    $("#allCheckChannelCluster").click(function() {
	    toggleStatus("idsChannelCluster","deleteButtonCluster",this.checked);
    });*/
    $("#allCheckChannelType").click(function() {
      	/*$('input[name="idsChannelType"]').prop("checked",this.checked);
      	if(this.checked){
        	$("#deleteButtonType").prop("disabled", false);
      	} else {
        	$("#deleteButtonType").prop("disabled", true);
      	}*/
      	toggleStatus("idsChannelType","deleteButtonType",this.checked);
	});
	  //ids为checkbox的name，deleteButton为删除按钮的id,checked是全选按钮的状态
	  function toggleStatus(ids,deleteButton,checked){
	  	  $('input[name="'+ids+'"]').prop("checked",checked);
	      console.info($('input[name="'+ids+'"]'));
		  if(checked){
		    $("#"+deleteButton).prop("disabled", false);
		  } else {
		    $("#"+deleteButton).prop("disabled", true);
		  }
	  }
      
      function statusToggle(ids,allCheckWho,deleteButton){
        $("#"+allCheckWho).prop("checked", $("input[name='"+ids+"']").length == $("input[name='"+ids+"']:checked").length ? true : false);
        var $idsChecked = $("[name='"+ids+"']:checked");
        if ($idsChecked.size() > 0) {
          $("#"+deleteButton).prop("disabled", false);
	    }else{
	      $("#"+deleteButton).prop("disabled", true);
	    }
      }      
      var $subBox = $("input[name='idsMember']");
      $subBox.click(function(){
        statusToggle("idsMember","allCheckMember","deleteButtonMember");
      });
      $subBox = $("input[name='idsStore']");
	  $subBox.click(function(){
		statusToggle("idsStore","allCheckStore","deleteButtonStore");
	  });
	  /*
	  $subBox = $("input[name='idsCity']");
	  $subBox.click(function(){
		statusToggle("idsCity","allCheckCity","deleteButtonCity");
	  });
	  $subBox = $("input[name='idsChannelClass']");
	  $subBox.click(function(){
		statusToggle("idsChannelClass","allCheckChannelClass","deleteButtonClass");
	  });
	  $subBox = $("input[name='idsChannelCluster']");
	  $subBox.click(function(){
		statusToggle("idsChannelCluster","allCheckChannelCluster","deleteButtonCluster");
	  });*/
	  $subBox = $("input[name='idsChannelType']");
	  $subBox.click(function(){
		statusToggle("idsChannelType","allCheckChannelType","deleteButtonType");
	  });


      /**
       *人员导入模板下载
       */
      $("#templateDownload").on('click', function(event) {
            location.href = "${base}/multiUserAuthConfig/template";
      });


});



    function deleteSelected(type) {
      var $idsCheckedCheck ;
      var $deleteButton ;// 删除按钮
      if(type==1){
        $idsCheckedCheck = $("[name='idsCity']:checked");//选中的ids
        $deleteButton = $("#deleteButtonCity");// 删除按钮
      }else if(type==2){
        $idsCheckedCheck = $("[name='idsStore']:checked");
        $deleteButton = $("#deleteButtonStore");
      }else if(type==3){
        $idsCheckedCheck = $("[name='idsMember']:checked");
        $deleteButton = $("#deleteButtonMember");
      }else if(type==4){
        $idsCheckedCheck = $("[name='idsChannelClass']:checked");
        $deleteButton = $("#deleteButtonClass");
      }else if(type==5){
        $idsCheckedCheck = $("[name='idsChannelCluster']:checked");
        $deleteButton = $("#deleteButtonCluster");
      }else if(type==6){
        $idsCheckedCheck = $("[name='idsChannelType']:checked");
        $deleteButton = $("#deleteButtonType");
      }
      
      //var ids = $idsCheckedCheck.serialize();
      var ids =[]; 
	  $idsCheckedCheck.each(function(){ 
		ids.push($(this).val()); 
	  });
	  ids = ids.join("#");
	  
	  url = urlBase + "/multiUserAuthConfig/deleteAuthorization?type="+type;
      if (confirm('您确定要删除吗？') == true) {
        $.ajax({
          url : url,
          data : {ids:ids},
          dataType : "json",
          async : false,
          beforeSend : function(data) {
            $deleteButton.prop("disabled", true)
          },
          success : function(data) {
            if(data.status=="success"){
	            $deleteButton.prop("disabled", false)
	            sendMessage({
	              title : "删除!",
	              text : data.message,
	              type : data.status,
	              timer : 2000,
	              showConfirmButton : false
	            });
	            query(type);
            }
          }
        });
      }
    }


    function deleteAll(type) {
        var typestr = {"1":"地市","2":"门店","3":"人员","4":"渠道大类","5":"渠道簇","6":"渠道小类"};
        var delete_url = urlBase + "/multiUserAuthConfig/deleteAllByType?type=3";
        if (confirm('您确定要删除所有'+typestr[type+""]+'授权数据吗？')) {
            $.ajax({
                url : delete_url,
                dataType : "json",
                async : false,
                success : function(data) {
                    if(data.status=="success"){
                        sendMessage({
                            title : "删除!",
                            text : data.message,
                            type : data.status,
                            timer : 2000,
                            showConfirmButton : false
                        });
                        query(type);
                    }
                }
            });
        }
    }








	function query(type) {
        var url = urlBase + "/multiUserAuthConfig/list?type="+type;
        url+= "&keywords=" + backKeyWordsStr();
        document.location.replace(url);
    }
    /*{}或者{"key":"value"}*/
    function backKeyWordsStr(){
        var keywordsObj={};//定义json，保存返回的关键字
        try{
            keywordsObj= JSON.parse('${keywords!""}');//获取以前的
        }catch(err){}
        console.info(keywordsObj);
        /*if($("#keyword-city").val()) {
            keywordsObj.keywordCity = $("#keyword-city").val();//添加现有的
        }else{
            if("keywordCity" in keywordsObj){
                delete keywordsObj["keywordCity"];
            }
        }*/
        if($("#keyword-org").val()) {
            keywordsObj.keywordOrg = $("#keyword-org").val();//添加现有的
        }else{
            if("keywordOrg" in keywordsObj){
                delete keywordsObj["keywordOrg"];
            }
        }
        if($("#keyword-member").val()) {
            keywordsObj.keywordMember = $("#keyword-member").val();//添加现有的
        }else{
            if("keywordMember" in keywordsObj){
                delete keywordsObj["keywordMember"];
            }
        }
        /*
        if($("#keywords-channel-class").val()) {
            keywordsObj.keywordChannelClass = $("#keywords-channel-class").val();//添加现有的
        }else{
            if("keywordChannelClass" in keywordsObj){
                delete keywordsObj["keywordChannelClass"];
            }
        }
        if($("#keywords-channel-cluster").val()) {
            keywordsObj.keywordChannelCluster = $("#keywords-channel-cluster").val();//添加现有的
        }else{
            if("keywordChannelCluster" in keywordsObj){
                delete keywordsObj["keywordChannelCluster"];
            }
        }*/
        if($("#keywords-channel-type").val()) {
            keywordsObj.keywordChannelType = $("#keywords-channel-type").val();//添加现有的
        }else{
            if("keywordChannelType" in keywordsObj){
                delete keywordsObj["keywordChannelType"];
            }
        }

        var keywords = JSON.stringify(keywordsObj);
        console.log("keywords = "+ keywords);
        return keywords;
    }


    //[{id:1},{id:2}]-->[1,2]
    function objProp2Arr(data){
        var ids = [];
        for(var i=0;i<data.length;i++){
            ids.push(data[i].id);
        }
        return ids;
    }

    function addAuthOrizationByType(type,ids,callback) {
        showWaitingHint("保存配置项，请稍候...");
        ids = ids.join("#");

        var url =  urlBase + "/multiUserAuthConfig/addAuthOrizationByType";
        $.ajax({
            url : url,
            type : 'POST',
            dataType : 'json',
            data :{ids:ids,type:type},
            cache : false,
            beforeSend : function(data) {
                // $('#orgID').selected('disable');
                // $("#submit-btn").prop("disabled", true);
            }
        }).done(function (result) {
            console.log('done.result:' + result);
            dismissWaitingHint();
            showDialog("操作成功", "", "success", 2000);
            callback(type);//刷新回去展示哪个tab
        }).fail(function () {
            console.log('fail');
            showDialog("操作失败", "", "error", 2000);
            dismissWaitingHint();
        });
    }
    
    
    function showDialog(msgTitle, message, msgType, msgTimer){
        sendMessage({
            title : msgTitle,
            text : message,
            type : msgType,
            timer : msgTimer,
            confirmButtonText : false
        });
    }




    function ajaxUploadFileWithLocalhost(id, url) {
        if($('#modal')){
            $('#modal').modal('open');
        }
        $.ajaxFileUpload({
            url : url,
            secureuri : false,
            fileElementId : id,// file标签的id
            dataType : 'json',// 返回数据的类型
            success : function(data, status) {
                if($('#modal')){
                    $('#modal').modal('close');
                }
                if (typeof (data.error) != 'undefined') {
                    alert(data.error);
                } else {
                    sendMessage({
                        title : (data.status==0)?"上传失败!":"上传完成!",
                        text : data.result,
                        type : "success",
                        confirmButtonText : "确认"
                    });
                    var path = window.location.pathname; //当前URL
                    var url = path + "?type=3";
                    //alert(url);
                    window.location.href=url;
                }
            },
            error : function(data, status, e) {
                if($('#modal')){
                    $('#modal').modal('close');
                }
                alert(e);
            }
        });
    }


  </script>
<%}%>